package Boke;

public class join2 {

        public static void main(String[] args) {
            System.out.println("主线程main，begin");
            Thread t1=new Thread(()->{
                System.out.println("线程t1,begin");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程t1,end");
            });
            t1.start();
            //让主线程等待t1结束，就在主线程中调用t1.join
            //等待t1线程执行结束后在继续执行线程T2
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Thread t2=new Thread(()->{
                System.out.println("线程t2,begin");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程t2,end");
            });
            t2.start();
            // //让主线程等待t2结束，就在主线程中调用t2.join
            try {
                t2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("主线程main,end");
        }

}
